package com.wyf.android.advance.rvvp

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.wyf.android.advance.R
import kotlinx.android.synthetic.main.fragment_rvvp.*
import java.util.ArrayList

class RvvpFragment : Fragment() {

    private val dataList = ArrayList<RVVPViewData>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        return inflater.inflate(R.layout.fragment_rvvp, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initData()
        initView()
    }

    private fun initData() {
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
        dataList.add(TopViewData("Fragment"))
    }

    private fun initView() {
        rv_list_test.apply {
            adapter = RVVP1Adapter()
        }
        (rv_list_test.adapter as RVVP1Adapter).submitList(dataList)
    }

    companion object {
        @JvmStatic
        fun newInstance() = RvvpFragment()
    }
}